package com.hq.commons.exception;

import com.hq.commons.common.R;
import com.hq.commons.exception.vo.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice
@Component
@Slf4j
public class Exception {

    @ExceptionHandler(java.lang.Exception.class)
    @ResponseBody
    public R systemException(Exception e) {
//        记录日志
        log.error("系统异常", e);
        return R.error("系统正在维护，请联系管理员!!!");
    }

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public R businessException(BusinessException e) {
        log.error("出现了业物异常", e);
        return R.error(e.getMsg());
    }
}
